<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: stats_keywords_all_print.php 115 2013-09-21 12:08:47Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 115 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:08:47 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require(DIR_FS_INC.'inc.image_submit.php');
require_once(DIR_FS_INC.'inc.parse_input_field_data.php');
require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body onload="window.print()" style="background: #fff">

<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
        <tr>
          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td class="main" valign="top"><?php echo HEADING_TITLE ?></td>
              </tr>
            </table></td>
        </tr>
        <tr>
        <td>
        <table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>          
		  <td valign="top">
          <table border="0" width="100%" cellspacing="0" cellpadding="2">
            <tr>
              <td width=105><?php
		

		echo draw_form('text_order', 'stats_keywords_all_print.php');
		echo draw_hidden_field('action','show_searches');
		echo draw_hidden_field('sortorder','search_text');
		echo draw_hidden_field('ascdsc','ASC');
		echo '<input type="submit" value="'.SORT_BY_NAME.'" class="button" />';
		echo "</form>\n</td>\n<td width=105>\n";

		echo draw_form('text_order', 'stats_keywords_all_print.php');
		echo draw_hidden_field('action','show_searches');
		echo draw_hidden_field('sortorder','search_count');
		echo draw_hidden_field('ascdsc','DESC');
		echo '<input type="submit" value="'.SORT_BY_COUNT.'" class="button" />';
		echo "</form>\n";

?>				 </td>

				</tr>
              </table></td>
            </tr>
            <tr>
            <td width="100%">
            <?php
	if ($_POST['action'] == 'deletedb') {
		$db->db_query("DELETE FROM search_queries_sorted");
	}


	if ($_POST['action'] == 'updatedb') {
		$keywords = $db->db_query("SELECT search_id, search_text, search_result FROM ".TABLE_SEARCH_QUERIES_ALL ." ORDER BY search_text");
			while (!$keywords->EOF) {
				$update_q_result = $db->db_query("SELECT search_text, search_count, search_result FROM ".TABLE_TABLE_SEARCH_QUERIES_SORTED ." WHERE search_text = '".$keywords->fields['search_text']."'");
				$count = 1 + $update_q_result->fields['search_count'];

				if ($update_q_result->fields['search_count'] != '') {
					$db->db_query("UPDATE IGNORE search_queries_sorted SET search_count = '".$count."' WHERE search_text = '".$keywords->fields['search_text']."'");
				} 
				else {
					$db->db_query("INSERT IGNORE INTO ".TABLE_SEARCH_QUERIES_SORTED ." (search_text, search_count, search_result) VALUES ('".$keywords->fields['search_text']."','1','".$keywords->fields['search_result'] ."')");
				}
				$db->db_query("DELETE FROM ".TABLE_SEARCH_QUERIES_ALL ." WHERE search_id = '".$keywords->fields['search_id']."'");
			$keywords->MoveNext();
			}
		}
?>
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_NUMBER; ?></td>
                <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_SEARCH_TOTAL; ?></td>
                <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_KEYWORD; ?></td>
                <?php if (LOG_PRODUCT_RETURNS == 'true') { ?>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_RETURNED; ?></td>
                <?php } ?>
              </tr>
              <?php	if ($_POST['action'] == 'show_searches') 
			show_search($_POST['sortorder'],$_POST['ascdsc']);
		else
			show_search('search_count','DESC');
	function show_search($search_by, $sort_order){
		global $db;
  		
		$keywords = $db->db_query("SELECT search_text, search_count, search_result FROM ".TABLE_SEARCH_QUERIES_SORTED ." ORDER BY '".$search_by. "' ".$sort_order."");

  		while(!$keywords->EOF) {
    		$rows++;

    		if(strlen($rows) < 2) 
      			$rows = '0'.$rows;
?>
              <tr>
                <td class="dataTableContent"><?php echo $rows; ?>.</td>
                <td class="dataTableContent">&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $keywords->fields['search_count']; ?></td>
                <td class="dataTableContent">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $keywords->fields['search_text']; ?></td>
                <?php	if(LOG_PRODUCT_RETURNS == 'true')
				echo '<td class="dataTableContent">'.$keywords->fields['search_result'].'</td>';
			$keywords->MoveNext();
  		} 
	}
?></tr></table>
              </td>
			  </tr>           
            </table>
            </td>
            </tr>
          </table>
          </td>
          </tr>
        </table>
      </table>
</table>

</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>
